package io.renren.config;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: xlr
 * @Date: Created in 下午12:51 2018/9/1
 */
@Configuration
public class ZKConfig {

    private Integer retryCount = 10;

    private Integer sleepMsBetweenRetries = 5000;

    private String hosts = "127.0.0.1:2181";

    private Integer timeOut = 1000;

    private Integer connectionTimeOut = 5000;

    @Bean
    public RetryNTimes restryPoly(){
        RetryNTimes retryNTimes = new RetryNTimes( retryCount, sleepMsBetweenRetries);
        return retryNTimes;
    }

    @Bean
    public CuratorFramework client(@Qualifier("restryPoly") RetryNTimes retryNTimes){
        CuratorFramework framework =CuratorFrameworkFactory.newClient( hosts,timeOut,connectionTimeOut,retryNTimes );
        return framework;
    }
}
